pub fn test_closures_fn() {
    demo1();
}


fn closure_fn<F>(func :F) 
where
F: Fn(),
{
    func();

    func();
}

fn closure_fn_mut<F>(mut func: F) 
where 
F: FnMut (),
{
    func();

    func();
}

fn closure_fn_once<F> (func :F)
where 
F: FnOnce(),
{
    func()
}
fn demo1() {
    // 不可变引用
    let s1 = String::from("11111");
    closure_fn(||println!("{s1}"));

    // 可变引用
    let mut s2 = String::from("222222");
    closure_fn_mut(|| println!("{s1}"));
    closure_fn_mut(||{
        s2.push_str("😁");
        println!("{s2}");
    });

    // FnOnce,所有权转移
    let s3 = "3333".to_owned();
    closure_fn_once(||println!("{s1}"));
    closure_fn_once(||println!("{s2}"));
    closure_fn_once(||println!("{s3}"));


}